package try_;

/**
 * @author 徐州城
 * @version 1.0
 */
public class TryCatchExercise01 {
    public static int method(){
        try {
            String[] names = new String[3];
            if (names[1].equals("tome")) { //空指针异常，因为names里面是null 不能用来操作
                System.out.println(names[1]);
            } else {
                names[3] = "xzc"; //索引越界
            }
            return 1;
        } catch (ArrayIndexOutOfBoundsException e){
            return 2;
        } catch (NullPointerException e) {
            return 3;
        } finally{ //必须执行
            return 4; //返回4
        }
    }

    public static void main(String[] args) {
        System.out.println(method()); //4
    }
}
